home *** CD-ROM | disk | FTP | other *** search
Wrap
/************************************************************************** * * @@@BUILDINFO@@@ 51print.jsx 1.0.0.53 23-Feb-2005 * Copyright 2005 Adobe Systems Incorporated * All Rights Reserved. * * NOTICE: All information contained herein is, and remains the property of * Adobe Systems Incorporated and its suppliers, if any. The intellectual * and technical concepts contained herein are proprietary to Adobe Systems * Incorporated and its suppliers and may be covered by U.S. and Foreign * Patents,patents in process,and are protected by trade secret or copyright * law. Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained from * Adobe Systems Incorporated. **************************************************************************/ // Printing Support. // Note that once the printer has been loaded, it cannot be unloaded anymore. // Unloading the DLL makes the code of all print objects goaway, leading to // a crash, because the objects may still exist in the JavaScript world. var printLib = null; var printer = null; var printerLoaded = false; var printerAvailable = true; // first, assume that printing is available until a load fails // return an RGB color array function getColor(color) { var c = new Array ; c[0] = (color & 0xff0000) >> 16 ; // R c[1] = (color & 0x00ff00) >> 8 ; // G c[2] = (color & 0x0000ff) >> 0 ; // B return c ; } // copy the prefs color data to the printer function setPrinterColors(printer,prefs) { var colors = printer.colors ; colors[0] = getColor(prefs.textColor) ; colors[1] = getColor(prefs.errorColor) ; colors[2] = getColor(prefs.keywordColor) ; colors[3] = getColor(prefs.numberColor) ; colors[4] = getColor(prefs.stringColor) ; colors[5] = getColor(prefs.symbolColor) ; colors[6] = getColor(prefs.operatorColor) ; colors[7] = getColor(prefs.commentColor) ; printer.colors = colors ; } // setup the correct font for printing/previewing function setPrinterFont(printer,prefs) { var bMac = $.os.substr (0, 3) == "Mac" ; var fontName = prefs.fontName ; if ( bMac ) { if ( fontName == "*serif" ) fontName = localize("$$$/ESToolkit/Fonts/SerifMac=Times" ) ; if ( fontName == "*sansserif" ) fontName = localize("$$$/ESToolkit/Fonts/SansSerifMac=Helvetica") ; if ( fontName == "*monospace" ) fontName = localize("$$$/ESToolkit/Fonts/MonospaceMac=Courier" ) ; } else { if ( fontName == "*system" ) fontName = localize("$$$/ESToolkit/Fonts/SystemWin=Arial Unicode MS" ) ; if ( fontName == "*application" ) fontName = localize("$$$/ESToolkit/Fonts/ApplicationWin=Arial Unicode MS") ; if ( fontName == "*serif" ) fontName = localize("$$$/ESToolkit/Fonts/SerifWin=Times New Roman" ) ; if ( fontName == "*sansserif" ) fontName = localize("$$$/ESToolkit/Fonts/SansSerifWin=Arial Unicode MS" ) ; if ( fontName == "*monospace" ) fontName = localize("$$$/ESToolkit/Fonts/MonospaceWin=Courier New" ) ; } printer.fontName = fontName ; printer.fontSize = prefs.fontSize; printer.fontFace = prefs.fontFace; } function printerSelected() { var result = false ; try { result = printer.printerNames.length > 0 ; } catch ( e ) {} ; try { if ( !result ) { printer = new PrintObject() ; } result = printer.printerNames.length > 0 ; } catch ( e ) {} ; if ( !result ) { errorBox(localize("$$$/ESToolkit/Alert/PrinterCountIsZero=Could not complete the Print command because the selected printer driver could not be found. Please select a printer from the control panel and try again.")) ; } return result ; } // Load the priner on demand. Return true if the printer is operational. function loadPrinter() { if (!printerLoaded) { var printLibPath = Folder.appPackage.absoluteURI; if ($.os.indexOf ("Mac") >= 0) printLibPath += "/Contents/PlugIns/printinglib"; else // Win printLibPath += "/Plug-Ins/printinglib"; try { printLib = new ExternalObject ("lib:" + printLibPath); } catch (e) { printLib = null; } printerLoaded = true; if (!printLib) { errorBox ("$$$/ESToolkit/Alerts/NoPrinter=Cannot load the printing library; printing is not available."); printerAvailable = false; } else printer = new PrintObject; } return printerAvailable; } var fileMenu = MenuElement.find ("file"); fileMenu.pageSetup = MenuElement.find ("file/pageSetup"); fileMenu.print = MenuElement.find ("file/print"); if ($.os.substr (0, 3) == "Win") fileMenu.preview = new MenuElement ( "command", localize ("$$$/ESToolkit/Menu/File/Preview=Print Pre&view"), "after file/pageSetup", "file/preview"); fileMenu.pageSetup.enabled = printerAvailable; fileMenu.print.onDisplay = function() { this.enabled = printerAvailable && (document != null) ; } if (fileMenu.preview) fileMenu.preview.onDisplay = fileMenu.print.onDisplay; fileMenu.pageSetup.onSelect = function() { if (loadPrinter() && printerSelected() ) printer.printSetup(); } if (fileMenu.preview) fileMenu.preview.onSelect = function() { if (loadPrinter()) { if (document.path) printer.fileName = document.path; else printer.fileName = document.title; setPrinterColors(printer,prefs) ; setPrinterFont (printer,prefs) ; printer.text = document.text; printer.tabs = prefs.tabs; printer.footer = "%c%d"; printer.lineNumbers = prefs.lineNumbers; printer.wrapLongLines = prefs.wrap; printer.preview(localize("$$$/ESToolkit/Alert/PrintPreviewTitle=Print Preview")); } } fileMenu.print.onSelect = function() { if (loadPrinter() && printerSelected() ) { if (document.path) printer.fileName = document.path; else printer.fileName = document.title; setPrinterColors(printer,prefs) ; setPrinterFont (printer,prefs) ; printer.text = document.text; printer.tabs = prefs.tabs; printer.footer = "%c%d"; printer.lineNumbers = prefs.lineNumbers; printer.wrapLongLines = prefs.wrap; printer.print(); } }